<?php

namespace App\Api\Controllers;

use App\Api\Dao\OrderDao;
use App\Api\Logic\GoodsGroupLogic;
use App\Api\Logic\OrderLogic;
use App\Exceptions\ValidationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class OrderController extends BaseController
{
    /**
     * 创建订单
     * @param Request $request
     * @param OrderLogic $orderLogic
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function addOrder(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->addOrder($params);
        $result = $orderDao->addOrder($params);
        return $this->success($result);
    }


    /**
     * 创建订单套餐
     * @return \Illuminate\Http\JsonResponse
     */
    public function addGroupOrder(Request $request,GoodsGroupLogic $goodsGroupLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $goodsGroupLogic->addGroupOrder($params);
        $result = $orderDao->addGroupOrder($params);
        return $this->success($result);
    }

    /**
     * 是否允许用户下多单
     * @return \Illuminate\Http\JsonResponse
     */
    public function moreGoods(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->moreGoods($params);
        $result = $orderDao->moreGoods($params);
        return $this->success($result);
    }


    /**
     * 获取订单列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function getOrderList(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->getOrderList($params);
        $result = $orderDao->getOrderList($params);
        return $this->success($result);
    }

    /**
     * 获取订单详情
     * @param Request $request
     * @param OrderLogic $orderLogic
     * @param OrderDao $orderDao
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     * @throws \App\Exceptions\DaoException
     */
    public function getOrderInfo(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->getOrderInfo($params);
        $result = $orderDao->getOrderInfo($params);
        return $this->success($result);
    }

    /**
     * 微信支付
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function wechatPay(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->wechatPay($params);
        $result = $orderDao->wechatPay($params);
        return $this->success($result);
    }

    /**
     * 修改订单收货地址
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     */
    public function updateOrderAddress(Request $request,OrderLogic $orderLogic,OrderDao $orderDao){
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->updateOrderAddress($params);
        $result = $orderDao->updateOrderAddress($params);
        return $this->success($result);
    }

    /**
     * 订单申请退款
     * @return void
     */
    public function applyOrderReturn(){
    }
}
